1. Field of the Invention
The present invention relates to performing arithmetic operations on interval operands within a computer system. More specifically, the present invention relates to a method and an apparatus for achieving a sharp (narrow as possible) interval result when subtracting a first or second interval operand from a third interval operand, given prior knowledge that the third interval operand is the sum of the first and second interval operands.
2. Related Art
Rapid advances in computing technology make it possible to perform trillions of computational operations each second. This tremendous computational speed makes it practical to perform computationally intensive tasks as diverse as predicting the weather and optimizing the design of an aircraft engine. Such computational tasks are typically performed using machine-representable floating-point numbers to approximate values of real numbers. (For example, see the Institute of Electrical and Electronics Engineers (IEEE) standard 754 for binary floating-point numbers.)
In spite of their limitations, floating-point numbers are generally used to perform most computational tasks.
One limitation is that machine-representable floating-point numbers have a fixed-size word length, which limits their accuracy. Note that a floating-point number is typically encoded using a 32, 64 or 128-bit binary number, which means that there are only 232, 264 or 2128 possible symbols that can be used to specify a floating-point number. Hence, most real number values can only be approximated with a corresponding floating-point number. This creates estimation errors that can be magnified through even a few computations, thereby adversely affecting the accuracy of a computation.
A related limitation is that floating-point numbers contain no information about their accuracy. Most measured data values include some amount of error that arises from the measurement process used to create the data values. This error can often be quantified as an accuracy parameter, which can subsequently be used to determine the accuracy of a computation. However, floating-point numbers are not designed to keep track of accuracy information, whether from input data measurement errors or machine rounding errors. Hence, it is not possible to determine the accuracy of a computation by merely examining a floating-point number that results from the computation.
Interval arithmetic has been developed to solve the above-described problems. Interval arithmetic represents numbers as intervals specified by a first (left) endpoint and a second (right) endpoint. For example, the interval [a, b], where axe2x89xa6b, is a closed, bounded subset of the real numbers, R, which includes a and b as well as all real numbers between a and b. Arithmetic operations on interval operands (interval arithmetic) are defined so that interval results always contain the entire set of possible values. The result is a mathematical system that rigorously bounds numerical errors from all sources, including measurement data errors, machine rounding errors and their interactions.
Note that the first endpoint normally contains the xe2x80x9cinfimumxe2x80x9d, which is the largest number that is less than or equal to each of a given set of real numbers. Similarly, the second endpoint normally contains the xe2x80x9csupremumxe2x80x9d, which is the smallest number that is greater than or equal to each of the given set of real numbers. One aspect of the present invention is directed to swapping the infimum and the supremum between the first endpoint and the second endpoint for representational purposes. Note that the infimum of an interval X can be represented as inf(X), and the supremum can be represented as sup(X).
Computer systems are presently not designed to efficiently handle intervals and interval computations. Consequently, performing interval operations on a typical computer system can be hundreds of times slower than performing conventional floating-point operations.
What is needed is a method and an apparatus that facilitates both efficient arithmetic operations on interval operands and interval results that are as narrow as possible. (Interval results that are as narrow as possible are said to be xe2x80x9csharpxe2x80x9d.)
In order to achieve sharp results, it is possible use knowledge of how operands were previously computed to narrow a resulting interval. For example, if we know that an interval X=A+B, the result of the interval subtraction operation R=Xxe2x88x92A can be narrowed to be [inf(X)-inf(A), sup(X)-sup(A)] instead of [inf(X)-sup(A), sup(A)-inf(A)]. Such a subtraction operation is known as a xe2x80x9cdependent subtraction operationxe2x80x9d because X and A are mathematically dependent as a consequence of the fact that X=A+B.
Because interval addition commutes, there is no need to distinguish between X=A+B and X=B+A. Similarly, there is no need to explicitly describe a dependent addition operation following an interval subtraction.
Although researchers have theoretically shown that dependent interval operations can be used to narrow resulting intervals, existing mechanisms to perform dependent interval operations have a number of shortcomings. They do not handle exception and non-exception conditions that arise in practical applications, such as dealing with infinite or empty intervals. Any invalid inputs that violate the dependence condition are termed exceptions.
What is needed is a method and an apparatus for performing dependent interval operations that efficiently handle exception conditions and invalid inputs.
One embodiment of the present invention provides a system for performing a dependent interval subtraction operation, wherein a first interval is subtracted from a third interval to produce a resulting interval, given knowledge that the third interval is the sum of the first interval and a second interval. If the left endpoint of the third interval is negative infinity, the left endpoint of the resulting interval is assigned to be negative infinity. Otherwise, the left endpoint of the resulting interval is computed by subtracting a left endpoint of the first interval from a left endpoint of the third interval using a floating-point arithmetic unit, and rounding down to a nearest smaller floating-point number. Similarly, if the right endpoint of the third interval is positive infinity, the right endpoint of the resulting interval is assigned to be positive infinity. Otherwise, the right endpoint of the resulting interval is computed by subtracting a right endpoint of the first interval from a right endpoint of the third interval using the floating-point arithmetic unit, and rounding up to a nearest larger floating-point number.
In one embodiment of the present invention, if both the first interval and the third interval are empty, computing the left endpoint of the resulting interval involves assigning the left endpoint of the resulting interval to be negative infinity, and computing the right endpoint of the resulting interval involves assigning the right endpoint of the resulting interval to be positive infinity.
In one embodiment of the present invention, if the first interval is not empty and the third interval is empty, the resulting interval is set to be empty.
In one embodiment of the present invention, if the first interval is empty and the third interval is not empty, a first exception case occurs. In this case, computing the left endpoint of the resulting interval involves assigning the left endpoint of the resulting interval to be negative infinity, and computing the right endpoint of the resulting interval involves assigning the right endpoint of the resulting interval to be positive infinity.
In one embodiment of the present invention, if the left endpoint of the first interval is negative infinity and the left endpoint of the third interval is not negative infinity, a second exception case occurs. In this case, computing the left endpoint of the resulting interval involves assigning the left endpoint of the resulting interval to be negative infinity, and computing the right endpoint of the resulting interval involves assigning the right endpoint of the resulting interval to be positive infinity.
In one embodiment of the present invention, if the right endpoint of the first interval is positive infinity and the right endpoint of the third interval is not positive infinity, a third exception case occurs. In this case, computing the left endpoint of the resulting interval involves assigning the left endpoint of the resulting interval to be negative infinity, and computing the right endpoint of the resulting interval involves assigning the right endpoint of the resulting interval to be positive infinity.
In one embodiment of the present invention, if the width of the third interval is less than the width of the first interval, a fourth exception case occurs. In this case, computing the left endpoint of the resulting interval involves assigning the left endpoint of the resulting interval to be negative infinity, and computing the right endpoint of the resulting interval involves assigning the right endpoint of the resulting interval to be positive infinity.
One embodiment of the present invention provides a system for compiling computer code to perform a subtraction operation between a first interval and a third interval to produce a resulting interval. The system operates by receiving source code within a compiler. The system next determines if a subtraction operation within the source code is a dependent subtraction operation, wherein the third interval is the sum of the first interval and a second interval. If so, the system produces executable code for the subtraction operation that computes a left endpoint for the resulting interval and a right endpoint for the resulting interval. If the left endpoint of the third interval is negative infinity, the left endpoint of the resulting interval is assigned to be negative infinity. Otherwise, the left endpoint of the resulting interval is computed by subtracting a left endpoint of the first interval from a left endpoint of the third interval using a floating-point arithmetic unit, and rounding down to a nearest smaller floating-point number. Similarly, if the right endpoint of the third interval is positive infinity, the right endpoint of the resulting interval is assigned to be positive infinity. Otherwise, the right endpoint of the resulting interval is computed by subtracting a right endpoint of the first interval from a right endpoint of the third interval using the floating-point arithmetic unit, and rounding up to a nearest larger floating-point number.